<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>单位管理</title>


    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/datapicker/datepicker3.css" rel="stylesheet">


</head>

<body class="gray-bg">
<div class="animated fadeInRight">

    <div class="row">

        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>单位信息查询</h5>
                    <!--<input type="button" id="btn1" value="行政区域" style="float: right;height: 30px">-->
                    <!--<input type="text"  class="form-control" id="txt1" style="float: right;margin-right: 10px;width: 30%;height: 30px;vertical-align: middle">-->


                </div>
                <div class="ibox-content " id="div1">
                    <div class="form-group">
                        <div class="col-sm-4">
                            <input id="txt1" placeholder="行政区域名称" class="form-control">
                        </div>
                        <div class="col-sm-4">
                            <button id="btn1" class="btn btn-primary">查询</button>
                        </div>
                    </div>
                    <table id="tab1" class="footable table table-stripped toggle-arrow-tiny" data-page-size="8"  >
                        <thead>
                        <tr>

                            <th data-toggle="true">单位名称</th>
                            <th>单位代码</th>
                            <th>所属级别</th>
                            <th>所属形式区域</th>
                            <th>上级单位代码</th>

                        </tr>
                        </thead>
                        <tbody >
                        <tr>
                            <td>龙江县公路站</td>
                            <td>010201</td>
                            <td>县级</td>
                            <td>龙江县</td>
                            <td>1502</td>
                            <td><a onclick="modify(this)"><i class="fa fa-wrench"></i> 修改</a></td>
                            <td><a onclick="remove(this)"><i class="fa fa-times"></i> 删除</a></td>
                        </tr>
                        <tr>
                            <td>哈尔滨市站</td>
                            <td>1500000</td>
                            <td>市级</td>
                            <td>哈尔滨市</td>
                            <td>1555555</td>
                            <td><a onclick="modify(this)"><i class="fa fa-wrench"></i> 修改</a></td>
                            <td><a onclick="remove(this)"><i class="fa fa-times"></i> 删除</a></td>
                        </tr>
                        <tr>
                            <td>道里区</td>
                            <td>150010</td>
                            <td>区级</td>
                            <td>哈尔滨</td>
                            <td>111</td>
                            <td><a onclick="modify(this)"><i class="fa fa-wrench"></i> 修改</a></td>
                            <td><a onclick="remove(this)"><i class="fa fa-times"></i> 删除</a></td>
                        </tr>

                        </tbody>

                        <tfoot>
                        <tr>
                            <td colspan="7">
                                <ul class="pagination pull-right"></ul>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>单位信息增加</h5>
                    <!--<div class="ibox-tools">-->
                    <!--<a class="collapse-link">-->
                    <!--<i class="fa fa-chevron-up"></i>-->
                    <!--</a>-->
                    <!--<a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">-->
                    <!--<i class="fa fa-wrench"></i>-->
                    <!--</a>-->
                    <!--<ul class="dropdown-menu dropdown-user">-->
                    <!--<li><a href="form_basic.html#">选项1</a>-->
                    <!--</li>-->
                    <!--<li><a href="form_basic.html#">选项2</a>-->
                    <!--</li>-->
                    <!--</ul>-->
                    <!--<a class="close-link">-->
                    <!--<i class="fa fa-times"></i>-->
                    <!--</a>-->
                    <!--</div>-->
                </div>
                <div class="ibox-content" class="form-horizontal">
                    <form method="get" class="form-horizontal" action="">
                        <div class="form-group" >
                            <label class="col-sm-2 control-label">单位名称</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group" >
                            <label class="col-sm-2 control-label">单位代码</label>
                            <div class="col-sm-8">
                                <input id="num" name="num" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属级别</label>
                            <div class="col-sm-8">
                                <input id="level" name="comment" class="form-control" required="" aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属形式区域</label>
                            <div class="col-sm-8">
                                <input type="text" id = "region" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">上级单位代码</label>
                            <div class="col-sm-8">
                                <input type="text" id = "fatherNum" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">

                                <button class="btn btn-primary" id="b1">保存内容</button>
                                <button class="btn btn-white" onclick="cancel()">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/plugins/footable/footable.all.min.js"></script>

<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>
<script type="text/javascript" src="js/unitsManage.js"></script>
<script src="js/plugins/datapicker/bootstrap-datepicker.js"></script>

<script>
    window.onload=function () {
        ajax('/company', {}, 'GET', function (str) {

            var Obj = eval("(" + str + ")");


            var otr = "";

            for (var i = 0; i < Obj.data.length; i++) {
                otr += "<tr ></tr>";
                otr += "<td style='display: none'>" + Obj.data[i].id + "</td>";
                otr += "<td>" + Obj.data[i].companyName + "</td>";
                otr += "<td>" + Obj.data[i].companyCode + "</td>";
                otr += "<td>" + Obj.data[i].levelCode + "</td>";
                otr += "<td>" + Obj.data[i].region.regionName + "</td>";
                otr += "<td>" + Obj.data[i].pcompanyCode + "</td>";
                otr += "<td>" + '<a class="a1" onclick=xiugai(this)><i class="fa fa-wrench"></i> 修改</a>' + "</td>";
                otr += "<td>" + '<a class="a2" onclick=shanchu(this)><i class="fa fa-wrench"></i> 删除</a>' + "</td>"
                //   onclick=shanchu(this)

            }

            document.getElementsByTagName('tbody')[0].innerHTML = otr;
        }, function () {
            alert('链接失败')
        })
        var oTab=document.getElementById("tab1");
        var oTxt=document.getElementById("txt1");
        var oBtn=document.getElementById("btn1");
        oBtn.onclick=function () {
            for(var i=0;i<=oTab.tBodies[0].rows.length;i++){
                var sTab=oTab.tBodies[0].rows[i].innerText.toLowerCase();
                var sTxt=oTxt.value.toLowerCase()
                if(sTab.search(sTxt)!=-1){

                    oTab.tBodies[0].rows[i].style.display="table-row";
                }
                else
                {
                    oTab.tBodies[0].rows[i].style.display="none"
                }
            }
        }

        var obtn=document.getElementById("b1");
        var cn;
        var cc;
        var lc;
        var ri;
        var pc;
        obtn.onclick=function(){
            cn=document.getElementById("name").value;
            cc=document.getElementById("num").value;
            lc=document.getElementById("level").value;
            ri=document.getElementById("region").value;
            pc=document.getElementById("fatherNum").value

            ajax('/company', {data: [{companyName:cn,
                    companyCode:cc,
                    levelCode:lc,
                    region:{id:ri},
                    pcompanyCode:pc}]}, 'POST',  console.log)

        }
    }

    function shanchu(cell) {
        var tr = cell.parentNode.parentNode;//input --> td --> tr
        var table = document.getElementsByTagName("table")[0]
                ajax('/company', {
                    data: [{
                        id:tr.cells[0].innerHTML
                    }]
                }, 'delete', function () {
                    table.deleteRow(tr.rowIndex)
                }, function () {
                    alert('失败')

                })

        }
        //修改
    function xiugai(cell){
         var tr = cell.parentNode.parentNode;//input --> td --> tr
        var text = tr.cells[4].innerText;
        //console.log(tr.cells[2].innerText);
        tr.cells[4].innerHTML = '<input id="comment' + tr.rowIndex + '" name="comment"' +
            'class="form-control" aria-required="true">';
        tr.cells[6].innerHTML = '<a onclick="queren(this)"><i class="fa fa-wrench"></i> 确认</a>';
        var comment = document.getElementById("comment" + tr.rowIndex);
        comment.value = text;
    }
    function queren(cell){
        var tr = cell.parentNode.parentNode;//input --> td --> tr
        // console.log(tr.cells[2].innerText);
        var comment=document.getElementById('comment' + tr.rowIndex).value;
        // alert(comment)
        ajax('/company', {data: [{id:tr.cells[0].innerHTML,
                region:{id:comment},
            }]}, 'PATCH', function () {
            tr.cells[4].innerHTML = comment;
            tr.cells[6].innerHTML = '<a onclick="xiugai(this)"><i class="fa fa-wrench"></i> 修改</a>';
        })
    }


</script>

<script type="text/javascript" src="js/service/service.js"></script>
</script>

<!--统计代码，可删除-->

</body>

</html>
